package org.baicaix.demo.hittest {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;

	/**
	 * @author dengyang
	 * @date 2010-4-22
	 */
	public class BitmapDataHitTest extends Sprite {
		
		private var bmap1 : Bitmap;
		private var bmap2 : Bitmap;
		private var bmapd1 : BitmapData;
		private var bmapd2 : BitmapData;

		public function BitmapDataHitTest() {
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			var star : Star = new Star(50);
			
			bmapd1 = new BitmapData(100, 100, true, 0);
			bmapd2 = new BitmapData(100, 100, true, 0);
			
			bmapd1.draw(star, new Matrix(1, 0, 0, 1, 50, 50));
			bmapd2.draw(star, new Matrix(1, 0, 0, 1, 50, 50));
			
			bmap1 = new Bitmap(bmapd1);
			bmap2 = new Bitmap(bmapd2);
			
			bmap1.x = 200;
			bmap1.y = 200;
			addChild(bmap1);
			addChild(bmap2);
			
			stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}

		private function mouseMoveHandler(event : MouseEvent) : void {
			bmap2.x = event.stageX - 50;
			bmap2.y = event.stageY - 50;
			
			if(bmapd1.hitTest(new Point(bmap1.x, bmap1.y), 255, bmapd2, new Point(bmap2.x, bmap2.y), 255)) {
				bmap1.filters = [new GlowFilter()];
				bmap2.filters = [new GlowFilter()];
			} else {
				bmap1.filters = [];
				bmap2.filters = [];
			}
		}
		
		
	}
}
